package model

import (
	"express/global"
	"express/handler/respone"
	"express/pkg/paginate"
	"express/pkg/time"
	"fmt"
)

type ExpressNumber struct {
	Id         int           `gorm:"primary_key" json:"id"`
	UserId     int           `label:"用户id" json:"user_id"`
	Number     string        `label:"快递单号" json:"number"`
	Status     int           `label:"1为已发出" gorm:"default:3" json:"status"`
	StatusName string        `json:"status_name"`
	NumNums    []NumNum      `gorm:"ForeignKey:ExpressId" json:"num_nums"`
	CreatedAt  time.JSONTime `json:"created_at"`
	UpdatedAt  time.JSONTime `json:"updated_at"`
}

func (ExpressNumber) TableName() string {
	return "express_number"
}

func (e *ExpressNumber) Create() (no bool, err error) {
	no = false
	err = fmt.Errorf("hello error")
	result := global.DB.Create(e)
	if result.Error != nil {
		return true, result.Error
	}
	return no, err
}

func (e *ExpressNumber) GetDateNumber(dateStart string, dateEnd string, userId string, page int, pageSize int) (expressNumber []respone.ExpressNumber) {
	global.DB.Model(&ExpressNumber{}).Where("user_id = ?", userId).Where("created_at > ?", dateStart).Where("created_at < ?", dateEnd).Scopes(paginate.Paginate(page, pageSize)).Find(&expressNumber)
	return
}
